import {RESCODE, RESMESSAGE} from './constant.js'

export class Result {
  code: number;
  data: any;
  message: string;
  constructor(code: number, data: any, message: string) {
    this.code = code;
    this.data = data;
    this.message = message;
  }


  static success(data: any, message?: string): Result {
    return new Result(RESCODE.SUCCESS, data, message || RESMESSAGE.SUCCESS);
  }

  static fail(data: any, message?: string): Result {
    return new Result(RESCODE.COMMFAIL, data, message || RESMESSAGE.COMMFAIL);
  }

  static validateFail(data: any, message?: string): Result {
    return new Result(RESCODE.VALIDATEFAIL, data, message || RESMESSAGE.VALIDATEFAIL);
  }

  static notFound(data: any, message?: string): Result {
    return new Result(RESCODE.NOTFOUND, data, message || RESMESSAGE.NOTFOUND);
  }

  static coreFail(data: any, message?: string): Result {
    return new Result(RESCODE.COREFAIL, data, message || RESMESSAGE.COREFAIL);
  }

  static noPermission(data: any, message?: string): Result {
    return new Result(RESCODE.NOPERMISSION, data, message || RESMESSAGE.NOPERMISSION);
  }
  static unauthorized(data: any, message?: string): Result {
    return new Result(RESCODE.UNAUTHORIZED, data, message || RESMESSAGE.UNAUTHORIZED);
  }

}
